$(function(){
    showDrugList();
});

function showDrugList(){
    API.table_get('pharmacy_promotion',{pharmacy:getParam('pharmacy'),p:getParam('p')},doShowPromotion);
}

function doShowPromotion(table_name,msg,getStatus){
    console.log(msg);
    if(getStatus){
        table_obj = $('#drug_table');
        //对相应的数据进行展示
        if(msg.length == 0){
            getNoneReplay();
            return false;
        }else{
            $('#has_no_msg').parent().empty();
            for(var i=0 ;i<msg.promotion_list.length;i++){
                temp = msg.promotion_list[i];
                tr = '<tr>';
                tr += '<td>' + temp.name + '</td>';
                tr += '<td>' + temp.content + '</td>';
                tr += '<td>' + temp.begin_time + '</td>';
                tr += '<td>' + ((temp.end_time) ? temp.end_time : '') + '</td>';
                tr += '<td>' + temp.detail + '</td>';
                tr += '<td>' + temp.created_at + '</td>';
                tr += '</tr>';
                table_obj.append(tr);
            }
        }
        //分页
        $('#page').createPage({
            pageCount:Math.ceil(msg.drug_count/20),
            current:parseInt(getParam('p')),
            backFn: function (p) {
                window.location.href = window.location.href.replace('p='+getParam('p'),'p='+p);
            }
        })
    }else{
        getNoneReplay();
    }

}

